from django.contrib import admin
from .models import CarbonFootprint, CarbonFactor, KnowledgeLog


@admin.register(CarbonFootprint)
class CarbonFootprintAdmin(admin.ModelAdmin):
    """碳足迹记录管理"""
    list_display = ['footprint_id', 'user', 'category', 'quantity', 'carbon_emission', 'record_date', 'created_at']
    list_filter = ['category', 'record_date', 'created_at']
    search_fields = ['user__id', 'category']
    ordering = ['-record_date']
    date_hierarchy = 'record_date'
    autocomplete_fields = ['user']
    list_per_page = 25


@admin.register(CarbonFactor)
class CarbonFactorAdmin(admin.ModelAdmin):
    """碳排放系数管理"""
    list_display = ['factor_id', 'item_name', 'category', 'emission_per_unit', 'unit']
    list_filter = ['category']
    search_fields = ['item_name', 'category']
    list_editable = ['category', 'emission_per_unit', 'unit']
    list_per_page = 25


@admin.register(KnowledgeLog)
class KnowledgeLogAdmin(admin.ModelAdmin):
    list_display = ['log_id', 'user', 'horizon_days', 'created_at']
    search_fields = ['user__username']
    list_filter = ['horizon_days', 'created_at']
    readonly_fields = ['items_json', 'prompt_text', 'created_at']
